<template>
    <!-- 
        .sync 用于实现prop双向绑定，同步修改值，父组件监听子组件传过来的值作用。
    -->
  <div :class="{ 'hidden': hidden }" class="container">
    <el-pagination
      :current-page.sync="currentPage"
      :page-size.sync="pageSize"
      :layout="layout"
      :page-sizes="pageSizes"
      :total="total"
      v-bind="$attrs"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
export default {
  name: 'Pagination',
  props: {
    // 总条目数
    total: {
      required: true,   // 必须传参
      type: Number
    },
    // 页码
    page: {
      type: Number,
      default: 1
    },
    // 限制范围
    limit: {
      type: Number,
      default: 10
    },
    // 每页显示条目数
    pageSizes: {
      type: Array,
      default() {
        return [10, 20, 30, 40]
      }
    },
    // 组件布局
    layout: {
      type: String,
      default: 'total, prev, pager, next, jumper'
    },
    background: {
      type: Boolean,
      default: true
    },
    autoScroll: {
      type: Boolean,
      default: true
    },
    hidden: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {};
  },
  computed: {
    // 当前页数
    currentPage: {
      get() {
        return this.page
      },
      set(val) {
        this.$emit('update:page', val)
      }
    },
    // 每页显示选择器的个数
    pageSizes: {
      get() {
        return this.limit
      },
      set(val) {
        this.$emit('update:limit', val)
      }
    }
  },
  methods: {
    handleSizeChange(val) {
      this.$emit('pagination', { page: this.currentPage, limit: val })
    },
    handleCurrentChange(val) {
      this.$emit('pagination', { page: val, limit: this.pageSize })
    }
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-pagination {
  text-align: right;
  padding-right: 100px;

    .btn-prev, .btn-next {
      color: #FF5F17;
    }
    span:not([class*=suffix]), button {
      color: #000000;
      font-size: 12px;
      padding: 0;
    }
    button:hover {
      color: #FF5F17;
      background: rgba(255, 95, 23, 0.15);
      border-radius: 8px;
      min-width: 26px;
      height: 26px;
      margin: 0px 5px;
    }
    .btn-prev, .btn-next {
      padding: 0;
    }
    .el-input--medium .el-input__inner {
      width: 32px;
      height: 22px;
      border-radius: 6px;
      border: 1px solid #FF5F17 !important;
      padding: 0 !important;
    }

    .el-pager li {
      color: #C4CED7;
    }
    .el-pager li.active {
      color: #FFFFFF;
      background-color: #000000;
      height: 26px;
      min-width: 26px;
      min-height: 26px;
      line-height: 26px;
      cursor: default;
      border-radius: 8px;
    }
    .el-pager li:hover {
      color: #FF5F17 ;
    }
}

.container {
  background: #fff;
}

.container.hidden {
  display: none;
}

</style>
